#!/usr/bin/env python
# encoding: utf-8

from rest_framework import routers


class LimitActionRouter(routers.SimpleRouter):
    """ Limit Some Route from urls
    """

    include = ()
    exclude = ()

    def __init__(self, trailing_slash=True, include=(), exclude=()):
        self.trailing_slash = '/' if trailing_slash else ''
        self.include = include
        self.exclude = exclude
        super(LimitActionRouter, self).__init__()

    def get_urls(self):
        urls = super(LimitActionRouter, self).get_urls()
        ret = []

        if self.include:
            for url in urls:
                if url.name in self.include:
                    ret.append(url)
        else:
            ret = urls[:]

        if self.exclude:
            for url in ret[:]:
                if url.name in self.exclude:
                    ret.remove(url)
        return ret
